#include "StateSyncCmd.h"

StateSyncCmd::StateSyncCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::CloudProtocol;
    this->m_functionCode = FunctionCode;
    this->m_state = 0;
    this->m_totalRamSize = 0;
    this->m_usedRamSize  = 0;
    this->m_totalFlashSize = 0;
    this->m_usedFlashSize  = 0;
}

Package StateSyncCmd::toPackage()
{
    Package package;
    QByteArray body;

    quint16 strLength;

    body.append(DataTypeConver::intToByteArray(m_state,1));

    body.append(DataTypeConver::intToByteArray(m_usedRamSize,4));

    body.append(DataTypeConver::intToByteArray(m_totalRamSize,4));

    body.append(DataTypeConver::intToByteArray(m_usedFlashSize,8));

    body.append(DataTypeConver::intToByteArray(m_totalFlashSize,8));

    strLength = m_runningTime.toLocal8Bit().length();
    body.append(DataTypeConver::intToByteArray(strLength,2));
    body.append(m_runningTime);

    strLength = m_ip.length();
    body.append(DataTypeConver::intToByteArray(strLength,2));
    body.append(m_ip);

    strLength = m_appVersion.length();
    body.append(DataTypeConver::intToByteArray(strLength,2));
    body.append(m_appVersion);

   // body = encrypt(body,KeyType::AES);

    package.setId(m_cmdId);
    package.setFunction(FunctionCode);
    package.setBody(body);

    return package;
}

void StateSyncCmd::unPackage(Package package)
{
    m_cmdId = package.id();
}

quint32 StateSyncCmd::totalRamSize() const
{
    return m_totalRamSize;
}

void StateSyncCmd::setTotalRamSize(const quint32 &totalRamSize)
{
    m_totalRamSize = totalRamSize;
}

quint32 StateSyncCmd::usedRamSize() const
{
    return m_usedRamSize;
}

void StateSyncCmd::setUsedRamSize(const quint32 &usedRamSize)
{
    m_usedRamSize = usedRamSize;
}

quint64 StateSyncCmd::totalFlashSize() const
{
    return m_totalFlashSize;
}

void StateSyncCmd::setTotalFlashSize(const quint64 &totalFlashSize)
{
    m_totalFlashSize = totalFlashSize;
}

quint64 StateSyncCmd::usedFlashSize() const
{
    return m_usedFlashSize;
}

void StateSyncCmd::setUsedFlashSize(const quint64 &usedFlashSize)
{
    m_usedFlashSize = usedFlashSize;
}


QString StateSyncCmd::ip() const
{
    return m_ip;
}

void StateSyncCmd::setIp(const QString &ip)
{
    m_ip = ip;
}

quint8 StateSyncCmd::state() const
{
    return m_state;
}

void StateSyncCmd::setState(const quint8 &state)
{
    m_state = state;
}

QString StateSyncCmd::appVersion() const
{
    return m_appVersion;
}

void StateSyncCmd::setAppVersion(const QString &appVersion)
{
    m_appVersion = appVersion;
}

QString StateSyncCmd::runningTime() const
{
    return m_runningTime;
}

void StateSyncCmd::setRunningTime(const QString &runningTime)
{
    m_runningTime = runningTime;
}
